<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>换肤效果</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      li {
        list-style: none;
      }

      body {
        background: url('./imgs/bg1.jpg') 0 0 no-repeat;
      }

      .box {
        width: 600px;
        margin: 100px auto;
      }
      .box ul {
        /* 清除浮动 */
        overflow: hidden;
      }
      .box li {
        float: left;
      }
      .box img {
        width: 150px;
        height: 100px;
        cursor: pointer;
      }

      .bg1 {
        background: url('./imgs/bg1.jpg') 0 0 no-repeat;
      }
      .bg2 {
        background: url('./imgs/bg2.jpg') 0 0 no-repeat;
      }
      .bg3 {
        background: url('./imgs/bg3.jpg') 0 0 no-repeat;
      }
      .bg4 {
        background: url('./imgs/bg4.jpg') 0 0 no-repeat;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <ul>
        <li class="img1"><img src="./imgs/bg1.jpg" /></li>
        <li class="img2"><img src="./imgs/bg2.jpg" /></li>
        <li class="img3"><img src="./imgs/bg3.jpg" /></li>
        <li class="img4"><img src="./imgs/bg4.jpg" /></li>
      </ul>
    </div>

    <script>
      var body = document.body;
      var img1 = document.querySelector('.img1');
      var img2 = document.querySelector('.img2');
      var img3 = document.querySelector('.img3');
      var img4 = document.querySelector('.img4');

      img1.onclick = function () {
        body.className = 'bg1';
      };
      img2.onclick = function () {
        body.className = 'bg2';
      };
      img3.onclick = function () {
        body.className = 'bg3';
      };
      img4.onclick = function () {
        body.className = 'bg4';
      };
    </script>
  </body>
</html>
